﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.TM
{
    public partial class SM_RoleList : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBindGv();
                //WorkFlowHelper wf = new WorkFlowHelper();
                //wf.TestWorkFlow();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected void DataBindGv()
        {
            string strWhere = string.Empty;
            strWhere = " where 1=1 ";
            if (txtRoleName.Value.Trim() != string.Empty)
                strWhere += " and name like '%" + txtRoleName.Value.Trim() + "%'";
            if (txtRoleDsc.Value.Trim() != string.Empty)
                strWhere += " and dsc like '%" + txtRoleDsc.Value.Trim() + "%'";
            int recount = 0;
            dlistData.DataSource = ZLDC.Topo.BLL.Estate.T_s_pdmBLL.GetPagerT_s_RoleList(strWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out recount);
            dlistData.DataBind();
            AspNetPager1.RecordCount = recount;
            ZLDC.Common.CmnFunc.setCustInfoOfAspnet(AspNetPager1);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            DataBindGv();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DataBindGv();
        }


        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("SM_RoleEdit.aspx");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void dlistData_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //删除角色
            if (e.CommandName == "delete")
            {
                string RoleID = e.CommandArgument.ToString();
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.DeleteT_s_Role_EmployeeByRoleID(RoleID);
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.DeleteRoel(RoleID);

                // 记录操作日志
                //ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("[192.168.168.80].zlhq.kfb.zldc_t_s_Role", _Convert.ToInt(RoleID, 0), "权限设置", "删除角色,ID:" + RoleID);

                DataBindGv();
            }

            if (e.CommandName == "Copy")
            {
                string RoleID = e.CommandArgument.ToString();
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.CopyRole(RoleID);
                Response.Write("<script>alert('复制成功');</script>");
                DataBindGv();
            }

        }

        protected void dlistData_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
            if (btnDelete != null)
            {
                btnDelete.Attributes.Add("onclick", "javascript:return confirm('确认是否删除该角色！');");
                HtmlInputHidden txtHidName = (HtmlInputHidden)e.Item.FindControl("txtHidName");
                HtmlGenericControl dvEdit = (HtmlGenericControl)e.Item.FindControl("dvEdit");

                HtmlGenericControl dvAccredit = (HtmlGenericControl)e.Item.FindControl("dvAccredit");
                if (txtHidName.Value == "系统管理员")
                {
                    btnDelete.Visible = false;
                    dvEdit.Visible = false;
                    dvAccredit.Visible = false;
                }

                HtmlTableRow trList = (HtmlTableRow)e.Item.FindControl("trList");
                trList.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#DDDDDD'");
                trList.Attributes.Add("onmouseout", "this.style.backgroundColor= c");
                if (e.Item.ItemIndex % 2 == 0)
                {
                    trList.Attributes.Add("style", "background-color:#f5f5f5");
                }
                else
                {
                    trList.Attributes.Add("style", "background-color:#ffffff");
                }
            }

        }
    }
}
